
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const express = require('express');
const app = express();
// test
const test = require('./routers/test');
// import {test} from './routers/test.js'
const cors = require('cors');
app.use(cors()) //解决跨域
app.use(express.json());//解析json请求
app.use(express.urlencoded({extended:false})) //解析URL-encoded请求
//创建server服务
app.listen(3307, () => {
    console.log('服务启动 port on run http://localhost:3307')
})
//设置跨域访问
app.all('*', (req, res, next) => {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
    res.header("X-Powered-By", ' 3.2.1');
    res.header("Content-Type", "application/json;charset=utf-8");
    next();
});
app.use('/test',test)
// app.get('/testGet', (req, res) => { // 测试get 请求
//     returnParams(req.query, res)
// })
//
// app.post('/testPost', (req, res) => { // 测试post 请求
//     returnParams(req.body, res)
// })

function returnParams(data, res) {
    res.json({ code: 1, status: 'S', data: data, msg: '成功' })
}